<?php
/**
 * Created by litong on Date: 2019/2/25 0025 上午 10:08
 */
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset = ($page-1)*$rows;
$sql="select count(*) from users";

include 'conn.php';
$connection = getConnection();
$mysqli_result=mysqli_query($connection,$sql); //返回mysqli_result,取出记录总数
$row_array=mysqli_fetch_row($mysqli_result);//取出mysqli_result中行的数据
$sql="select * from users limit $offset,$rows";
$mysqli_result = mysqli_query($connection, $sql); //查询数据库
$items=array();
while($row=mysqli_fetch_object($mysqli_result)){ //将mysqli_result转为object
  array_push($items,$row);//将row的数据添加到items队列中
}
//构建返回值
$retval_array = array();
$retval_array["total"]=$row_array[0];
$retval_array["rows"]=$items;
$retval=json_encode($retval_array);
echo $retval;